<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Http\Models\Post;
use App\Http\Models\PostCid;

class UploadController extends Controller {


    public function upload(Request $request)
    {
        $time = time();
        $directory = env("UPLOAD_DIRECTORY")?rtrim(env("UPLOAD_DIRECTORY"),'/'):"upload";
        $directory = $directory.'/'.date('Y',$time).'/'.date('m').'/'.date('d');
        $name = $time.".".$request->Filedata->extension();
        $res =  $request->Filedata->move($directory,$name);
        $ret = ["url"=>"/public/".$directory."/".$name,"status"=>'ok'];

        return json_encode($ret);
    }


    public function editorUpload(Request $request)
    {
        $time = time();
        $directory = env("UPLOAD_DIRECTORY")?rtrim(env("UPLOAD_DIRECTORY"),'/'):"upload";
        $directory = $directory.'/'.date('Y',$time).'/'.date('m').'/'.date('d');
        $name = $time.".".$request->wangEditorH5File->extension();
        $res =  $request->wangEditorH5File->move($directory,$name);
        $url = "/public/".$directory."/".$name;
        return $url;
        
    }


}
